﻿<!DOCTYPE html>
<!--字典管理-->
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="/static/js/common.js"></script>

    <script src="../static/js/Mock/RisksManagement.js"></script>
    <script src="../static/js/Resource/RisksManagement.js"></script>
    <link href="../static/js/vue-treeselect/vue-treeselect.css" rel="stylesheet" />
    <script src="../static/js/vue-treeselect/vue-treeselect.js"></script>
    <style>
        .vue-treeselect__control {
            height: 100%;
            border: none;
            background: none;
        }

        .vue-treeselect__placeholder {
            top: -3px;
        }

        .vue-treeselect__single-value {
            top: -3px;
        }

        .el-dialog__body {
            height: 100% !important;
        }

        .el-dialog__body iframe {
            height: 100% !important;
        }

        .el-dialog.is-fullscreen {
            overflow: hidden !important;
        }

        .el-dialog__wrapper {
            position: absolute !important;
        }
    </style>
</head>

<body>

    <div id="app" v-cloak>
        <el-row>
            <el-col :span="24">
                <el-form label-position="right" ref="form" :inline="true" :model="formInline" class="demo-form-inline"
                    style="margin-bottom: 15px;">
                    <el-row>
                        <el-col class="head-tool">
                            <div class="new_title fl">
                                <strong><img src="/static/images/icon1.png" />字典管理列表</strong>
                            </div>
                            <span>
                                <btn :text="col.btnSelect" imgsrc="/static/images/search.png" linetype="3"
                                    @click="onSubmit"></btn>
                                <btn :text="col.btnAdd" linetype="3" @click="UserInput('tj')"></btn>
                                <btn :text="col.btnDelete" linetype="4" @click="onDelete"></btn>
                            </span>
                        </el-col>
                    </el-row>
                    <el-row>
                        <el-col :xs="12" :sm="8" :md="6" :lg="6" :xl="6">
                            <div class="elst-select-mini">
                                <el-form-item>
                                    <el-input v-model="formInline.model.Category" :placeholder="SysDict.Category"
                                        size="mini">
                                        <template slot="prepend">
                                            {{SysDict.Category+mark.m}}
                                        </template>
                                    </el-input>
                                </el-form-item>
                            </div>
                        </el-col>
                        <el-col :xs="12" :sm="8" :md="6" :lg="6" :xl="6">
                            <div class="elst-select-mini">
                                <el-form-item>
                                    <el-input v-model="formInline.model.Value" :placeholder="SysDict.Value" size="mini">
                                        <template slot="prepend">
                                            {{SysDict.Value+mark.m}}
                                        </template>
                                    </el-input>
                                </el-form-item>
                            </div>
                        </el-col>
                    </el-row>

                </el-form>
                <el-table ref="table" :data="ListItem.tableData" :height="ListItem.tableHeight" border
                    @selection-change="handleSelectionChange" row-style="height:10px" :span-method="objectSpanMethod"
                    :default-sort="{prop: 'SerialNumber', order: 'ascending'}" style="width: 100%">
                    <el-table-column type="selection" align="center" width="55">
                    </el-table-column>

                    <el-table-column type="index" :label="SysDict.No" :index="indexMethod" width="50"
                        show-overflow-tooltip="true">

                    </el-table-column>
                    <el-table-column prop="category" :label="SysDict.Category" min-width="80" show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column prop="value" :label="SysDict.Value" show-overflow-tooltip="true" min-width="200">
                    </el-table-column>

                    <el-table-column prop="key" :label="SysDict.Key" min-width="200" show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column prop="serialNumber" :label="SysDict.SerialNumber" min-width="200"
                        show-overflow-tooltip="true">
                    </el-table-column>
                    <el-table-column prop="remarks" :label="SysDict.Remarks" show-overflow-tooltip="true" min-width="100">
                    </el-table-column>
                    <el-table-column width="53" prop="update" :label="col.btnUpdate" fixed="right">
                        <template slot-scope="scope">
                            <button type="button" class="elst-bt-xg" @click=UserInput('xg',scope.row.id)>
                                <i class="el-icon-edit"></i>
                            </button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-col>
        </el-row>
        <el-dialog fullscreen="true" title="字典管理" :visible.sync="ListItem.dialogVisible" @close='closeDialog' width="80%" height="80%"
            top="10vh">
            <iframe ref="iframe" :src="ListItem.InputUrl" style="height:95%;width:100%" frameborder="0"></iframe>
        </el-dialog>
    </div>
    <script type="text/javascript">
        Vue.component('treeselect', VueTreeselect.Treeselect)
        app = new Vue({
            el: '#app',
            data: function () {
                return {
                    //页面内数据初始化
                    ListItem: ListItem,
                    spanArr: [],
                    formInline: {
                        model: {
                            Category: '',//分组类别
                            Value: '',//名称
                        },
                        offset: 0,
                        limit: 10
                    },
                }
            },
            created: function () { },
            mounted: function () {
                //初始化数据
                this.DataSerialization(this);
                //列表高度自适应
                tablehigh(this);
            },
            methods: {
                //解決edge下select bug
                visibleChange: function (isVisible) {
                    visibleChange(isVisible)
                },
                //表格序号连续化
                indexMethod: function (index) { return (this.ListItem.currentPage - 1) * this.ListItem.pagesize + index + 1; },
                //删除方法
                closeDialog: function () { this.DataSerialization(this) },
                onDelete: function () {
                    var mythis = this;
                    var url = '/api/DataDir/DeleteMuti';
                    if (mythis.ListItem.tableMultipleSelection.length == 0) {
                        showMessage(msg.AtLeastOne, 'error')
                        return;
                    }
                    mythis.$confirm(' 是否确认继续?', '提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(function () {
                        var delIds = [];
                        for (var i = 0; i < mythis.ListItem.tableMultipleSelection.length; i++) {
                            var item = mythis.ListItem.tableMultipleSelection[i];
                            delIds.push(item.id);
                        }
                        myAjax("post", mythis, url, delIds, function (response) {
                            mythis.DataSerialization(mythis)
                            showMessage(msg.OperatingOk, "success");
                        });
                    }).catch(function () {
                        showMessage("已取消删除!");
                    });
                },
                //列表选择触发
                handleSelectionChange: function (val) { handleSelectionChange(this, val); },
                //Dialog展示
                UserInput: function (val, id) { DialogShow(this, val, "SysDictInput.html", id); },
                //获取分页数据
                GetPageData: function (currentIndex) { myAjax("post", this, '/api/DataDir/GetList', this.formInline, function (response) { this.ListItem.tableData = response.data; }, false); },
                //数据序列化
                DataSerialization: function (mythis) {
                    mythis.GetPageData(1);
                    mythis.ListItem.tableData.sort(function (a, b) { return a.serialNumber > b.serialNumber ? 1 : -1 })//排序
                    mythis.getSpanArr(mythis.ListItem.tableData);
                },
                //查询方法
                onSubmit: function () { onSubmit(this); },
                //合并行
                objectSpanMethod: function (row, column, rowIndex, columnIndex) {
                    //声明列对象，行对象
                    var columnIndex = row.columnIndex, rowIndex = row.rowIndex
                    //判断需要合并的列
                    if (columnIndex === 2) {
                        //读取当前行的合并数量
                        var _row = this.spanArr[rowIndex];
                        //console.log('输出合并行序列',rowIndex, _row)
                        //如果当前行合并，则对应列为1，否则0（0为不显示）
                        var _col = _row > 0 ? 1 : 0;
                        return [_row, _col]
                    }
                },
                getSpanArr: function (data) {
                    //生成合并行数据组
                    this.spanArr = [];
                    var spanArr = this.spanArr;
                    //console.log('Begin', this.spanArr);
                    //初始化行号
                    var c = 0;
                    //遍历数据
                    //this.ListItem.tableData.forEach(function (v, i) {
                    data.forEach(function (v, i) {
                        //第一条数据固定
                        if (i === 0) {
                            spanArr.push(1);

                        }
                        else {
                            //如果当前数据跟上一条数据id相同，则合并行数据+1，并且填充0合并行
                            if (v.category === data[i - 1].category) {
                                spanArr[c] += 1;
                                spanArr.push(0);
                            }
                            else {
                                //如果不相同，则重置合并数量，且更改合并行数据组索引
                                spanArr.push(1);
                                c = i;
                            }
                        }
                    })
                    //console.log('End', this.spanArr);
                },
            }
        });
    </script>
</body>

</html>